package dabs.engine;
import dabs.engine.environment.*;

public class Reactor extends Converter implements AcceptsModifier{
	private int rodLevel;
	private boolean rodsFault;
	private int timeToFault;
	private int timeLeftFault;
	
	
	public Reactor(PowerPlant plant, String name, int conversionRate, int rodLevel) {
		super(plant, name, conversionRate);
		this.rodLevel = rodLevel;
		rodsFault = false;
		timeToFault = 0;
		timeLeftFault = 0;
	}
	
	public int getRodLevel() { return rodLevel; }
	
	public void setRodLevel(int rodLevel) { 
		if (rodsFault == false){ this.rodLevel = rodLevel; }
		else { 
			super.passMessage(new Notification("Reactor", 
					"Rod's have stalled. Back online in " + timeLeftFault + " seconds!"));
		}
	}
	
	public void handleModifier(Modifier modifier) {
		if (modifier instanceof TemporaryDisable){
			super.passMessage(new Notification(super.getName(), 
					"Rod's stalling in 30 seconds!"));
			timeToFault = 30;
			timeLeftFault = modifier.getDuration();
		}
	}
	
	public void tick(){
		if (timeToFault == 1){
			timeToFault--;
			rodsFault = true;
			super.passMessage(new Notification("Reactor",
					"Rods are offline for " + timeLeftFault + " seconds!"));
		}
		else if (timeToFault > 1) { timeToFault--; }
		else if (rodsFault == false) { super.tick(); }
		else {
			if (timeLeftFault == 0){
				super.passMessage(new Notification("Reactor", 
						"Rods are back online."));
				rodsFault = false; 
				}
			else { timeLeftFault--; }
		}
	}
}
